package com.gl.rent;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.dto.HousingAllocationDTO;
import com.haixiaoke.saas.repository.pojo.House;
import com.haixiaoke.saas.repository.service.IHouseService;
import com.haixiaoke.saas.repository.vo.HousingAllocationVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 房屋表saas_houseController
 * 
 * @author haixiaoke
 * @date 2023-04-10
 */
@RestController
@RequestMapping("/saas-repository/house/apartment")
public class HouseApartmentController extends BaseController {
    @Autowired
    private IHouseService houseService;

    /**
     * 查询房屋表saas_house列表
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(HousingAllocationDTO house) {
        startPage();
        List<HousingAllocationVO> list = houseService.selectHouseList(house);
        return getDataTable(list);
    }

    /**
     * 获取房屋表saas_house详细信息
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:house:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(houseService.selectHouseById(id));
    }

    /**
     * 统计公寓房屋上下架数量
     * @return
     */
    @GetMapping(value = "/countNum")
    public AjaxResult getCount() {
        return success(houseService.selectCount());
    }

    /**
     * 新增房屋表saas_house
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:house:add')")
//    @Log(title = "房屋表saas_house", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody House house) {
        return toAjax(houseService.insertHouse(house));
    }

    /**
     * 修改房屋表saas_house
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:house:edit')")
//    @Log(title = "房屋表saas_house", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody House house) {
        return toAjax(houseService.updateHouse(house));
    }

    /**
     * 删除房屋表saas_house
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:house:remove')")
//    @Log(title = "房屋表saas_house", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(houseService.deleteHouseByIds(ids));
    }
}
